package cn.limc.ohoscharts.demo.slice;

import cn.limc.ohoscharts.demo.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.ListContainer;

import java.util.ArrayList;
import java.util.List;

public class MainAbilitySlice extends AbilitySlice {

  private String[] mListTitle = {"GridChart", "LineChart", "SlipLineChart", "SlipAreaChart",
      "SlipBandAreaChart", "StickChart", "SlipStickChart", "ColoredSlipStickChart",
      "MAStickChart", "MASlipStickChart", "MinusStickChart", "SlipMinusStickChart",
      "CandleStickChart", "SlipCandleStickChart", "MACandleStickChart",
      "MASlipCandleStickChart", "BOLLMASlipCandleStckChart", "MACDChart", "PieChart",
      "RoseChart", "SpiderWebChart", "RadarChart", "DonutChart"};

  private String[] mListStr = {"view.GridChart",
      "view.LineChart", "view.SlipLineChart",
      "view.SlipAreaChart",
      "view.SlipBandAreaChart",
      "view.StickChart", "view.SlipStickChart",
      "view.ColoredSlipStickChart",
      "view.MAStickChart",
      "view.MASlipStickChart",
      "view.MinusStickChart",
      "view.SlipMinusStickChart",
      "view.CandleStickChart",
      "view.SlipCandleStickChart",
      "view.MACandleStickChart",
      "view.MASlipCandleStickChart",
      "view.BOLLMASlipCandleStickChart",
      "view.MACDChart", "view.PieChart",
      "view.RoseChart", "view.SpiderWebChart",
      "view.RadarChart", "view.DonutChart"};

  private AbilitySlice slice;
  private Intent intent;

  @Override
  public void onStart(Intent intent) {
    super.onStart(intent);
    super.setUIContent(ResourceTable.Layout_ability_main);
    initListContainer();
  }

  private void initListContainer() {
    ListContainer listContainer = (ListContainer) findComponentById(ResourceTable.Id_ChartListView);
    List<SampleItem> list = getData();
    SampleItemProvider sampleItemProvider = new SampleItemProvider(list, this);
    listContainer.setItemProvider(sampleItemProvider);
    listContainer.setBindStateChangedListener(new Component.BindStateChangedListener() {
      @Override
      public void onComponentBoundToWindow(Component component) {
        sampleItemProvider.notifyDataChanged();
      }

      @Override
      public void onComponentUnboundFromWindow(Component component) {
      }
    });

    listContainer.setItemClickedListener((container, component, position, id) -> {
      SampleItem item = (SampleItem) listContainer.getItemProvider().getItem(position);
      switch (position) {
        case 0:
          slice = new GridChartAbility();
          intent = new Intent();
          present(slice, intent);
          break;
        case 1:
          slice = new LineChartAbility();
          intent = new Intent();
          present(slice, intent);
          break;
        case 2:
          slice = new SlipLineChartAbility();
          intent = new Intent();
          present(slice, intent);
          break;
        case 3:
          slice = new SlipAreaChartAbility();
          intent = new Intent();
          present(slice, intent);
          break;
        case 4:
          slice = new SlipBandAreaChartAbility();
          intent = new Intent();
          present(slice, intent);
          break;
        case 5:
          slice = new StickChartAbility();
          intent = new Intent();
          present(slice, intent);
          break;
        case 6:
          slice = new SlipStickChartAbility();
          intent = new Intent();
          present(slice, intent);
          break;
        case 7:
          slice = new ColoredSlipStickChartAbility();
          intent = new Intent();
          present(slice, intent);
          break;
        case 8:
          slice = new MAStickChartAbility();
          intent = new Intent();
          present(slice, intent);
          break;
        case 9:
          slice = new MASlipStickChartAbility();
          intent = new Intent();
          present(slice, intent);
          break;
        case 10:
          slice = new MinusStickChartAbility();
          intent = new Intent();
          present(slice, intent);
          break;
        case 11:
          slice = new SlipMinusStickChartAbility();
          intent = new Intent();
          present(slice, intent);
          break;
        case 12:
          slice = new CandleStickChartAbility();
          intent = new Intent();
          present(slice, intent);
          break;
        case 13:
          slice = new SlipCandleStickChartAbility();
          intent = new Intent();
          present(slice, intent);
          break;
        case 14:
          slice = new MACandleStickChartAbility();
          intent = new Intent();
          present(slice, intent);
          break;
        case 15:
          slice = new MASlipCandleStickChartActivity();
          intent = new Intent();
          present(slice, intent);
          break;
        case 16:
          slice = new BOLLMASlipCandleStickChartAbility();
          intent = new Intent();
          present(slice, intent);
          break;
        case 17:
          slice = new MACDChartAbility();
          intent = new Intent();
          present(slice, intent);
          break;
        case 18:
          slice = new PieChartAbility();
          intent = new Intent();
          present(slice, intent);
          break;
        case 19:
          slice = new RoseChartAbility();
          intent = new Intent();
          present(slice, intent);
          break;
        case 20:
          slice = new SpiderWebChartAbility();
          intent = new Intent();
          present(slice, intent);
          break;
        case 21:
          slice = new RadarChartAbility();
          intent = new Intent();
          present(slice, intent);
          break;
        case 22:
          slice = new DonutChartAbility();
          intent = new Intent();
          present(slice, intent);
          break;
      }
    });
  }

  private ArrayList<SampleItem> getData() {
    ArrayList<SampleItem> list = new ArrayList<>();
    for (int i = 0; i <= 22; i++) {
      list.add(new SampleItem(mListTitle[i], mListStr[i]));
    }
    return list;
  }

  @Override
  public void onActive() {
    super.onActive();
  }

  @Override
  public void onForeground(Intent intent) {
    super.onForeground(intent);
  }
}
